package com.baomidou.ant.service.impl;

import com.baomidou.ant.entity.SignInfo;
import com.baomidou.ant.entity.User;
import com.baomidou.ant.mapper.SignInfoMapper;
import com.baomidou.ant.service.ISignInfoService;
import com.baomidou.ant.service.IUserService;
import com.baomidou.ant.utils.compareDate;
import com.baomidou.ant.vo.Request.RequestSignInVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2021-03-24
 */
@Service
public class SignInfoServiceImpl extends ServiceImpl<SignInfoMapper, SignInfo> implements ISignInfoService {
    @Autowired
    private IUserService userService;

    @Override
    public boolean sign(RequestSignInVo requestSignInVo) {
        //获取当前时间
        LocalDateTime date=LocalDateTime.now();
        //先查询签到纪录
        QueryWrapper<SignInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",requestSignInVo.getUserId());
        SignInfo signInfo=getOne(queryWrapper);
        //更新数据
        signInfo.setSignTimes(signInfo.getSignTimes()+1);
        signInfo.setSignIn(date);
        saveOrUpdate(signInfo);
        return true;
    }

}
